package com.lianziyou.coin.price.util;

import static com.lianziyou.coin.price.service.IGetPriceService.COIN_PRICE_REDIS_HASH_KEY;

import com.lianziyou.coin.price.vo.PriceVO;
import java.math.BigDecimal;
import org.cloud.core.redis.RedisUtil;

public final class CoinPriceUtil {

    private CoinPriceUtil() {

    }
    public BigDecimal getUsdtPrice(String coinSymbol) {
        return getPrice(coinSymbol + "_USDT");
    }

    public void setUsdtPrice(String coinSymbol, BigDecimal price) {
        RedisUtil.single().hashSet(COIN_PRICE_REDIS_HASH_KEY, coinSymbol + "_USDT", PriceVO.builder().pairName(coinSymbol + "_USDT").price(price).build());

    }

    public BigDecimal getPrice(String pairName) {
        PriceVO priceVO = RedisUtil.single().hashGet(COIN_PRICE_REDIS_HASH_KEY, pairName);
        return priceVO == null ? null : priceVO.getPrice();
    }

    private static CoinPriceUtil instance = new CoinPriceUtil();

    public static CoinPriceUtil single() {
        return instance;
    }
}
